
#include "midea_base_scroll_cell.h"

#define MY_CLASS &midea_base_scroll_cell_class

// static void midea_base_scroll_cell_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
// static void midea_base_scroll_cell_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);

const lv_obj_class_t midea_base_scroll_cell_class = {
    // .constructor_cb = midea_base_scroll_cell_constructor,
    // .destructor_cb = midea_base_scroll_cell_destructor,
    .width_def = LV_SIZE_CONTENT,
    .height_def = LV_SIZE_CONTENT,
    .base_class = &lv_obj_class,
    .instance_size = sizeof(midea_base_scroll_cell)};

// static void midea_base_scroll_cell_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
// {
//     LV_UNUSED(class_p);
//     midea_base_scroll_cell * page = (midea_base_scroll_cell *)obj;
//     page->page_swap_tag = MIDEA_CIRCLE_PAGE_SWAP_DEFAULT;
// }

// static void midea_base_scroll_cell_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
// {
//     LV_UNUSED(class_p);
//     midea_base_scroll_cell * page = (midea_base_scroll_cell *)obj;
//     if (page->name != NULL) {
//         lv_mem_free(page->name);
//         page->name = NULL;
//     }
// }

lv_obj_t *midea_base_scroll_cell_create(lv_obj_t *parent)
{
    lv_obj_t *cell = lv_obj_class_create_obj(MY_CLASS, parent);
    lv_obj_class_init_obj(cell);
    midea_base_scroll_cell *base_cell = (midea_base_scroll_cell *)cell;
    base_cell->ui_type = ((1 << 8) - 2); // 为了让初始化的ui_type不常用 不和常用的冲突
    return cell;
}

void midea_base_scroll_cell_set_ui_type(lv_obj_t *cell, uint8_t ui_type)
{
    if (!lv_obj_has_class(cell, MY_CLASS))
    {
        return;
    }
    midea_base_scroll_cell *base_cell = (midea_base_scroll_cell *)cell;
    base_cell->ui_type = ui_type;
}

uint8_t midea_base_scroll_cell_get_ui_type(lv_obj_t *cell)
{
    if (!lv_obj_has_class(cell, MY_CLASS))
    {
        return 0;
    }
    midea_base_scroll_cell *base_cell = (midea_base_scroll_cell *)cell;
    return base_cell->ui_type;
}

//@brief 比较ui_type是否一致
//@param cell 目标cell
//@param ui_type 对比的ui_type
//@return true or false
bool midea_base_scroll_cell_is_same_ui_type(lv_obj_t *cell, uint8_t ui_type)
{
    if (!lv_obj_has_class(cell, MY_CLASS))
    {
        return false;
    }
    midea_base_scroll_cell *base_cell = (midea_base_scroll_cell *)cell;
    return base_cell->ui_type == ui_type;
}